// @(#)thread.cc
// Time-stamp: <2008-11-21 04:12:38 root>
// Copyright 2008 Julian Qian
// Author: root@localhost.localdomain
// Version: $Id: thread.cc,v 0.0 2008/11/18 07:39:15 root Exp $
// Keywords: 

#include "thread.hh"
// #include "common.hh"
// #include "log.hh"


Thread::Thread(){
    pthread_attr_init(&_attr);
    pthread_attr_setdetachstate(&_attr, PTHREAD_CREATE_JOINABLE); // default: jionable
}

Thread::~Thread(){
    // if(0 == _ret) join();
}

void
Thread::detach(){
    // ptrhead_attr_setdetachstate(&_attr, PTHREAD_CREATE_DETACHED);
    pthread_detach(_pid);
}

void
Thread::join(){
    pthread_join(_pid, NULL);
}

bool
Thread::run(Functype func, void* param){
    if(_ret = pthread_create((pthread_t*)&_pid, &_attr, (Functype)func, param)){
        // LFatal("Create thread failed!");
        return false;
    }
    return true;
}
